package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.OrderSettingDao;
import com.itheima.pojo.OrderSetting;
import com.itheima.service.OrderSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service(interfaceClass = OrderSettingService.class)
@Transactional
public class OrderSettingServiceImpl implements OrderSettingService {

    @Autowired
    private OrderSettingDao orderSettingDao;

    //添加
    @Override
    public void add(List<OrderSetting> list) {
        //遍历该元素
        for (OrderSetting orderSetting : list) {
            //查询是否包含该日期
            Integer count = orderSettingDao.findCountByOrderDate(orderSetting.getOrderDate());
            //判断
            if(count>0){
                //该元素已经存在数据库
                orderSettingDao.update(orderSetting);
            }else {
                //该元素不存在
                orderSettingDao.add(orderSetting);
            }
        }

    }

    //查询每天的预约
    @Override
    public List<Map> getOrderSettingByMonth(String date) {
        List<Map> list = orderSettingDao.getOrderSettingByMonth(date);
        return list;
    }

    //预约设置
    @Override
    public void editOrderSettingByDate(OrderSetting orderSetting) {
        orderSettingDao.editOrderSettingByDate(orderSetting);
    }
}
